import java.util.ArrayList;
import java.util.List;


public class P49 {
	public static void main(String[] args) {
		List<Integer> primeList = new ArrayList<Integer>();
		
		for (int i = 1001; i <= 9999; i++) {
			if (Util.isPrime(i)) {
				primeList.add(i);				
			}
		}
		
		for (int i = 0; i < primeList.size(); i++) {
			int a = primeList.get(i);
			for (int j = i + 1; j < primeList.size(); j++) {
				int b = primeList.get(j);
				
				int diff = b - a;
				int c = b + diff;
				
				if (primeList.contains(c)) {
					if (Util.isPermuation(a, b, c)) {
						System.out.println(a + "," + b + "," + c);
					}
				}
			}
		}
		System.out.println(primeList.size());
	}
}